package at.ac.univie.zsu.aguataplan.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;

/**
 * @author gerry
 * 
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Working {

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column
	private Long id;

	@Version
	@Column
	private Integer version;

	@OneToMany(cascade = CascadeType.ALL)
	private Set<WorkingDescription> refWorkingDescription = new HashSet<WorkingDescription>();

	@ManyToOne
	private Player refPlayer;

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public Working() {

	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("RefPlayer: ").append(getRefPlayer()).append(", ");
		sb.append("RefWorkingDescription: ")
				.append(getRefWorkingDescription() == null ? "null"
						: getRefWorkingDescription().size()).append(", ");
		sb.append("Version: ").append(getVersion());
		return sb.toString();
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Set<WorkingDescription> getRefWorkingDescription() {
		return refWorkingDescription;
	}

	public void setRefWorkingDescription(
			Set<WorkingDescription> refWorkingDescription) {
		this.refWorkingDescription = refWorkingDescription;
	}

	public Player getRefPlayer() {
		return refPlayer;
	}

	public void setRefPlayer(Player refPlayer) {
		this.refPlayer = refPlayer;
	}

}
